/*****************************************************************
**                                                              **
**  Copyright (C) 2004 Amlogic,Inc.                             **
**  All rights reserved                                         **
**        Filename : aw_user.c /Project:AVOS                    ** 
**        Revision : 1.0                                        **
**                                                              **
*****************************************************************/

#include "../menu.h"
#include "includes.h"
#include "aw_windows.h"
#include "app.h"
#include "user.h"
#include "menu.h"
#include "aw_init_display.h"
#include "logo_dat.h" 
#include "LogoEvent.h"
#include "filelistevent.h"
#include "aw_sys_app.h"
#include "aw_gui_app.h"
#include "filenav.h"
#include "ctrlconvert.h"
#include "DeviceSelectEvent.h"
#ifdef ENABLE_BLUETOOTH
#include "aw_bluetooth.h"
#endif
#ifdef ENABLE_NETWORK_BASIC
    #include <filesystem/extend/fileio.h>
    #include "filenav.h"
    #include "net_app.h"
    #include "netdiskdev.h"
    #include "filesystem/netfs/netfs.h"
    int my_fs_interrupt_cb(void* arg);
    int my_file_rdwr_interrupt_cb(void* arg);
    extern INT8U menu_index;
#endif
#ifdef ENABLE_NETWORK
    #include "win/Network_SetupEvent.h"
    static AVTimer_t process_quit_timer = 0;
    extern INT8U  network_connected_flag;
    extern INT8U menu_index_process;
#endif

static INT8U show_mount_flag=0;
INT8U Yahoo_already_connected        = 0;
INT8U Google_already_connected       = 0;
INT8U FrameChannel_already_connected = 0;

char multi_vol_autorun = 0;
char temp_curdriver[10];
char autorun_audio_flag = 0;
char autorun_video_flag = 0;
char autorun_pic_flag = 0;
char copy_flag = NOCOPY ;
extern INT8U WinTypeChoice;

extern INT8U FileListOnShowFlag;
extern INT32U ONLYDIR_FLAG;
extern INT32U NODIR_FLAG;
extern int upgrade_flag;
extern char CurDriver[10];

static INT8U max_volume = 1;
static char temp_mount_point_name[10]="/mnt/B";
static char temp_mount_device_name[30]="device";

INT8U copy_del_flag = SYS_FINISH_FILE ;

extern unsigned char PC_Connect;
extern unsigned char PerpheralDevRemoved;
static unsigned char ForceCloseMediaApp = 0;

void SetForceCloseMediaApp()
{
	ForceCloseMediaApp = 1;
}
void CleanForceCloseMediaApp()
{
	ForceCloseMediaApp = 0;
}
unsigned char GetForceCloseMediaApp()
{
	return ForceCloseMediaApp;
}

extern int check_media_file_exist(char* path_name ,unsigned media_type,int search_way);

extern void Cut_string(char *str);

INT8U SystemCommandResponse(AWMSG *pMsg, PCMDSET cmd_set)
{
    INT8U iRet = BREAK_EXECUTE_COMMAND ;
    switch(pMsg->msg_type)
    {
        case MSG_COMMAND_SUCCESS:
//            copy_del_flag = SYS_CMD_SUCCESS ;
            WinUpdateSysPlayStatus(copy_del_flag, 0) ;
            iRet = GO_ON_EXECUTE_COMMAND ;
            break ;
        case MSG_COMMAND_FAIL:
            copy_del_flag = SYS_ERROR ;
            WinUpdateSysPlayStatus(copy_del_flag, (pMsg->msg_value==(INT32U)(-SYS_DISK_FULL))?COPY_DEL_DISKFULL_ERROR:COPY_DEL_NORMAL_ERROR) ;
            break ;
        case MSG_COMMAND_FORBIDEN:
            copy_del_flag = SYS_ERROR ;
            WinUpdateSysPlayStatus(copy_del_flag, 0) ;
            break ;
        case MSG_COMMAND_NOT_SUPPORT:
        default:
            copy_del_flag = SYS_ERROR ;
            WinUpdateSysPlayStatus(copy_del_flag, 0) ;
            break ;
    }
    return iRet;
}
#ifdef ENABLE_NETWORK_BASIC 
static void Warning_timer_func(void *arg)
{
    if(AWGetTopWindow(gpFocusWin) == AWFindWinCtrlByName("WinWarnMessageBox")) 
    {
        AWGUISendNMMessage(MEDIA_SYSTEM, NM_SHOW_DEVICEWIN, 0);
    }
    
}

unsigned char Is_Gallery(char* device_type)
{
    if((strcmp("GALLERY",device_type)==0)||(strcmp("RSS_GALLERY",device_type)==0)
        ||(strcmp("FLI_GALLERY",device_type)==0)||(strcmp("PIC_GALLERY",device_type)==0)||(strcmp("FRAMECHANNEL",device_type)==0)
#ifdef RSS_GALLERY_SUPPORT
        ||(strcmp("RSS_GALLERY",device_type)==0)
#endif
        )    
        return 1;
    else 
        return 0;    
    
}
#endif   


static INT32S FileCopy(const char *sur_file, const char *dst_file, INT8U copy_flag)
{
	int     i_ret=0;
	FILECOPY_T *pCopyData;
	PCMDSET pCmd ;

	pCopyData = (FILECOPY_T*)AVMem_umalloc(sizeof(FILECOPY_T));
	if(!pCopyData)
	{
		return -ENOMEM;
	}

	pCopyData->sour_file = (char *)AVMem_umalloc(MAXPATHLEN);
	if(!pCopyData->sour_file)
	{
		AVMem_free(pCopyData);
		return -ENOMEM;
	}
	memset(pCopyData->sour_file, 0, MAXPATHLEN);
	
	pCopyData->dest_file = (char *)AVMem_umalloc(MAXPATHLEN);
	if(!pCopyData->dest_file)
	{
		AVMem_free(pCopyData);
		AVMem_free(pCopyData->sour_file);		
		return -ENOMEM;
	}
	memset(pCopyData->dest_file, 0, MAXPATHLEN);

    sprintf(pCopyData->sour_file,  "%s",  sur_file) ;
    sprintf(pCopyData->dest_file,  "%s",  dst_file) ;
	pCopyData->flag = copy_flag ;
	
	pCmd = AWCommandSetMalloc() ;
	pCmd->command_num = 1 ;
	pCmd->curr_executed_cmd_num = 0 ;
	pCmd->commands[0] = CM_FILE_COPY ;
	pCmd->commands_para[0] = (INT32U)pCopyData;
	pCmd->cmd_timeout_value[0] = 0 ;
	AWGetAppID(MEDIA_SYSTEM, &pCmd->app_id) ;
	pCmd->ExecuteResultProcess = SystemCommandResponse ;
	AWAddCommandSet(pCmd) ;
	
//    gpCurrentPathNode->path_info.path_type &= ~NAV_CHILD_PARSERED_FLAG ;
    
    return i_ret;
}

int FileOperationCancel()
{
	int     i_ret=0;
	PCMDSET pCmd ;

	pCmd = AWCommandSetMalloc() ;
	pCmd->command_num = 1 ;
	pCmd->curr_executed_cmd_num = 0 ;
	pCmd->commands[0] = CM_STOP ;
	pCmd->commands_para[0] = 0;
	pCmd->cmd_timeout_value[0] = 0 ;
	AWGetAppID(MEDIA_SYSTEM, &pCmd->app_id) ;
	pCmd->ExecuteResultProcess = NULL ;
	AWAddCommandSet(pCmd) ;
        return i_ret;    
}    

int AWSysCopyDelFile(char *copy_del, INT8U flag)
{
	PCMDSET pCmd ;
    char *file_name ;
    char *file_path ;
    char *gPasteFileName ;
    int name_len ;
    FILEDEL_T *pDelData;
    
    copy_del_flag = flag ;
    WinUpdateSysPlayStatus(copy_del_flag, 0) ;
    file_name = strrchr(copy_del, '/') ;
    String_Updata_FileName(file_name, infobar_filename, SYS_INFOBAR_NAME_LENGTH) ;
    Cut_string(infobar_filename);
    if(copy_del_flag == SYS_COPY_FILE) {
        name_len = strlen(file_name);
        file_path = FileNavGetCurrDir() ;
        name_len += strlen(file_path);
        gPasteFileName = (char *)AVMem_umalloc(name_len + 1) ;
        if(gPasteFileName){
            snprintf(gPasteFileName, name_len, "%s%s",  file_path, &file_name[1]) ;
            gPasteFileName[name_len] = 0;
            if(FileCopy(copy_del, gPasteFileName, 1) != 0){ //success
                copy_del_flag = SYS_ERROR ;
                WinUpdateSysPlayStatus(copy_del_flag, 0) ;
            }
            AVMem_free(gPasteFileName) ;
            
        }
        else {
	     FileListOnShowFlag=0;
            GUIShowWindow(WinFileList) ;
            return 1 ; 
        }
    }
    else {
        pDelData=(FILEDEL_T*)AVMem_umalloc(sizeof(FILEDEL_T));
	if(pDelData) {
            pDelData->file = copy_del ;
            pDelData->time = 200 ; // delay 200 ms
    		pCmd = AWCommandSetMalloc() ;
    		pCmd->command_num = 1 ;
    		pCmd->curr_executed_cmd_num = 0 ;
    		pCmd->commands[0] = CM_FILE_DEL ;
    		pCmd->commands_para[0] = (INT32U)pDelData;
    		pCmd->cmd_timeout_value[0] = 2 ; //2S
    		AWGetAppID(MEDIA_SYSTEM, &pCmd->app_id) ;
    		pCmd->ExecuteResultProcess = SystemCommandResponse ;
    		AWAddCommandSet(pCmd) ;
		}
		else {
            copy_del_flag = SYS_ERROR ;
            WinUpdateSysPlayStatus(copy_del_flag, 0) ;
		}
    }
    return 0 ;
}

void AWSysKeyProcess(INT32U* iInputKey)
{
    switch(*iInputKey)
    {
        case UOP_OPEN_CLOSE:
            break ;
    }
    return ;
}

INT8U AWSysGetDriverNum()
{
    INT32U dir_num;
    PATHNODE DesList;
    int i=0;
    while(1){
        dir_num=1;
        FileNavGetNextFileListRandom("/mnt/", i, &DesList, &dir_num, 0xffffffff);
        if(dir_num==0)
            break;
        i++;            
    }
    return i ;
}

void AWSysNotificationProcess(AWMSG *pMsg)
{
    char *file_name ;
#ifdef ENABLE_BLUETOOTH
	AWBTNotificationProcess(pMsg);
#endif
    switch(pMsg->msg_id){
        case NM_DOING_PROCESS_CHANGE:
        	if(copy_del_flag == SYS_COPY_FILE){
        		if(copy_flag == NOCOPY){
            		WinUpdateSysPlayStatus(copy_del_flag, pMsg->msg_value & 0xff) ;
            		copy_flag = COPYING ;
            	}
        	}
        	else {
        		WinUpdateSysPlayStatus(copy_del_flag, pMsg->msg_value & 0xff) ;
        	}
            break ;
			#ifdef ENABLE_NETWORK
		case NM_SHOW_DEVICEWIN:
			AWHideWindowByName("WinWarnMessageBox");
			AWShowWindowByName("WinDeviceSelect", 1);
			ReloadLogo(Logo_keyboard, sizeof(Logo_keyboard));
			break;
		case NM_SHOW_NETWORK_ICON:
			PHWND hwnd=AWFindWinCtrlByName("WinDeviceSelectInfo") ;
			if(AWGetTopWindow(gpFocusWin) == AWFindWinCtrlByName("WinDeviceSelect"))
			{	
				AWPostMessage(hwnd, WM_PAINT, 0) ;
				AWPostMessage(hwnd, WM_PAINT_FINISH, 0) ;
			}
			break;	
		#endif

        case NM_END_OF_PLAY:
        	
			switch(pMsg->msg_value){
				case SYS_NO_ERROR:
	            file_name = AWGetNextPlaylistItem(MEDIA_GENERAL) ;
	            if(file_name){
	//                UpdateSysPlayFileName(file_name) ;
	                AWSysCopyDelFile(file_name, copy_del_flag) ;
	            }
	            else {
	                copy_del_flag = SYS_FINISH_FILE ;
	                WinUpdateSysPlayStatus(copy_del_flag, 100) ;
	            }
	            break ;
	    			case -SYS_DISK_FULL:
	    				copy_del_flag = SYS_ERROR;
	    				WinUpdateSysPlayStatus(copy_del_flag, COPY_DEL_DISKFULL_ERROR) ;
	    				break;
				case -SYS_IO_ERROR:
				case -SYS_DIR_NOT_EMPTY:
				case -SYS_FILE_COPY_FAIL:
				case -SYS_FILE_CLOSE_FAIL:
				default:
	                copy_del_flag = SYS_ERROR;
	                    WinUpdateSysPlayStatus(copy_del_flag, COPY_DEL_NORMAL_ERROR) ;
	                    break ;
			}
			copy_flag = NOCOPY ;	
            	break ;
    }
    return ;
}

void AWSysQuitProcess(AWMSG *pMsg)
{
    return;
}

INT8U CheckMediaPlaybackApp()
{
    INT8U my_app_id ;
    
    AWGetAppID(MEDIA_PIC, &my_app_id) ; 
    if (AWGetAppStatus(my_app_id) == APP_RUNNING)
            return 1;
    
    AWGetAppID(MEDIA_AVI, &my_app_id) ; 
    if (AWGetAppStatus(my_app_id) == APP_RUNNING)
            return 1;
    
    AWGetAppID(MEDIA_MPEG1, &my_app_id) ;
    if (AWGetAppStatus(my_app_id) == APP_RUNNING)
            return 1;  
    
    AWGetAppID(MEDIA_MPEG2, &my_app_id) ; 
    if (AWGetAppStatus(my_app_id) == APP_RUNNING)
            return 1; 
         
    AWGetAppID(MEDIA_GENERAL, &my_app_id) ; 
    if (AWGetAppStatus(my_app_id) == APP_RUNNING)
            return 1;
    
    AWGetAppID(MEDIA_MP3, &my_app_id) ; 
    if (AWGetAppStatus(my_app_id) == APP_RUNNING)
            return 1;  
    
    AWGetAppID(MEDIA_WMA, &my_app_id) ; 
    if (AWGetAppStatus(my_app_id) == APP_RUNNING)
            return 1;  
    
#ifdef SUPPORT_RM
    AWGetAppID(MEDIA_REAL, &my_app_id) ; 
    if (AWGetAppStatus(my_app_id) == APP_RUNNING) {
        return 1;
    }
#endif   
    return 0;
}

void MultiVolumeAutoRun()
{
		
	strcpy(temp_curdriver,CurDriver);
	temp_curdriver[5]-=max_volume;
		
	for(INT8U i=0;i<max_volume;i++){
		if((check_media_file_exist(CurDriver,(MEDIA_PIC | AW_VIDEO_LIST | AW_AUDIO_LIST),0x300|0x1)))
		{	
			if(AWGetTopWindow(gpFocusWin) == AWFindWinCtrlByName(WinLogo)
				&&(NODIR_FLAG==1))
			{
				if(check_media_file_exist(CurDriver,(AW_AUDIO_LIST),0x300|0x1)){
					
					PHWND hwnd = AWFindWinCtrlByName(FileListView);
					if(hwnd)
						AWHideWinControl(hwnd); 							
					if(CheckMediaPlaybackApp())
						CloseMediaPlaybackApp(0xff);
					autorun_audio_flag = 1;
					return;
				}
				else if(i == max_volume - 1)
				{
					strcpy(CurDriver, temp_curdriver);
				}

			}
			if(AWGetTopWindow(gpFocusWin) == AWFindWinCtrlByName(WinLogo)
				&&(NODIR_FLAG == 2))
			{
				if(check_media_file_exist(CurDriver,(AW_VIDEO_LIST),0x300|0x1)){
					
					if(CheckMediaPlaybackApp())
						CloseMediaPlaybackApp(0xff);			
					autorun_video_flag = 1;
					return;
				}
				else if(i == max_volume - 1)
				{
					strcpy(CurDriver, temp_curdriver);
				}
			}
			if(AWGetTopWindow(gpFocusWin) == AWFindWinCtrlByName(Win15Pic))
			{
				if(check_media_file_exist(CurDriver,(AW_PIC_LIST),0x300|0x1))
				{

					if(CheckMediaPlaybackApp())
						CloseMediaPlaybackApp(0xff);

					autorun_pic_flag = 1;						
					return;
				}
				else if(i == max_volume - 1)
				{
					strcpy(CurDriver, temp_curdriver);
				}
			}
		}
		if(i < max_volume - 1)
			CurDriver[5]++;
		else
			strcpy(CurDriver, temp_curdriver);
	}
}


void CurDriverAutoSet()
{
    if(max_volume == 0)
        return;
	
	for(CurDriver[5] ='C';CurDriver[5]<='Z';CurDriver[5]++)
	{    
		if(FileNavDirExists(CurDriver))
		{
		    return;	
		}
    }
	CurDriver[5] = 'C';
}

void AWSysBroadCastProcess(AWMSG *pMsg)
{
	char* mount_type;
	DEV_MOUNT_INFO DevMountInfo;
	PHWND hwnd = NULL;
#ifdef ENABLE_BLUETOOTH
	AWBTBroadCastProcess(pMsg);
#endif		
	switch(pMsg->msg_id){
		case BM_DEVICE_POST_MOUNT:
			
		    mount_type=((DEV_MOUNT_INFO *)(pMsg->msg_value))->mount_device_type;
#if 0//def ENABLE_BLUETOOTH	
			if(strcmp(mount_type,"BTOPP")==0)
				break;
#endif
#ifdef ENABLE_NETWORK  
        if (Is_Gallery(mount_type))
        {
            NetFs_SetPar(((DEV_MOUNT_INFO *)(pMsg->msg_value))->mount_point_name,mount_type);
            //menu_index_process=ID_MENU_CONNECT_SUCCESS;	  

            if (strcmp("FLI_GALLERY", mount_type) == 0)
            {
                int mount_fd;
                Yahoo_already_connected=1;

                if (menu_index_process == ID_MENU_CONNECT_NETWORK)
                {
                    show_mount_flag=1;   	
                }

                menu_index_process = ID_MENU_CONNECT__SUCCESS1;	          		
#ifndef YAHOO_GUEST_MODE_ONLY
                mount_fd = open(((DEV_MOUNT_INFO *)(pMsg->msg_value))->mount_point_name,0);
                if(mount_fd>=0){
                    NetDisk_Dev_Info_t* netdisk_dev_info;
                    ioctl(mount_fd,FILE_IOCTL_GET_DEV_INFO,&netdisk_dev_info);
 //                   if(netdisk_dev_info->data_ext)
 //                       SetFlickrFullToken((unsigned char*)netdisk_dev_info->data_ext);
                    close(mount_fd);                        
                }                        
#endif                
                
            } 
            else if (strcmp("PIC_GALLERY", mount_type) == 0)
            {           
                Google_already_connected=1;

                if (menu_index_process == ID_MENU_CONNECT_NETWORK)
                {
                    show_mount_flag=1;
                }

                menu_index_process = ID_MENU_CONNECT__SUCCESS2;	
            }
            else if (strcmp("FRAMECHANNEL", mount_type) == 0)
            {           
                FrameChannel_already_connected = 1;

                if (menu_index_process == ID_MENU_CONNECT_NETWORK)
                {
                    show_mount_flag=1;
                }

                menu_index_process = ID_MENU_CONNECT_SUCCESS_FRAMECHANNEL;	
            }
#ifdef RSS_GALLERY_SUPPORT
            else if (strcmp("RSS_GALLERY", mount_type) == 0)
            {           
                NetDisk_SetOpt_Req_t setopt_req;
                setopt_req.type=NETDISK_SETTYPE_RSS_ADD_FEED;
                setopt_req.data[0]=(unsigned)"Flick";
                setopt_req.data[1]=(unsigned)"http://api.flickr.com/services/feeds/photos_public.gne?id=90056637@N00&tags=mauihyatt&format=rss_200";
                NetDiskSetOpt(((DEV_MOUNT_INFO *)(pMsg->msg_value))->mount_point_name,&setopt_req);

                setopt_req.data[0]=(unsigned)"PICASA";
                setopt_req.data[1]=(unsigned)"http://picasaweb.google.com/data/feed/back_compat/user/jerry.cao?kind=album&alt=rss";
                NetDiskSetOpt(((DEV_MOUNT_INFO *)(pMsg->msg_value))->mount_point_name,&setopt_req);
            }
#endif
            if (AWGetTopWindow(gpFocusWin) == AWFindWinCtrlByName("Network_Setup"))
            {   	
                PHWND dir_hwnd = AWFindWinCtrlByName("Internet_Setting") ;
                if(AWIsVisibleWinControl(dir_hwnd))
                {
//                    ReloadLogo(Logo_Setup, sizeof(Logo_Setup));  
//		      change_message(menu_index_process);
		      
                    GUIShowWindow("WinWarnMessageBox");

                    if (!process_quit_timer) 
                        process_quit_timer = AVTimerCreateFlag(STAYING_TIME, Warning_timer_func , NULL, AVTIMER_FLAG_NONE | AVTIMER_FLAG_AUTO_DELETE);	    		
                    else
                        AVTimerRestart(process_quit_timer);
                }
            }
            else if (AWGetTopWindow(gpFocusWin) == AWFindWinCtrlByName("WinWarnMessageBox")) 
            {
                if(show_mount_flag==1)
                {	
                    show_mount_flag=0;
   //                 change_message(menu_index_process);
                    repaint_message();   	

                    if (!process_quit_timer) 
                        process_quit_timer = AVTimerCreateFlag(STAYING_TIME, Warning_timer_func , NULL, AVTIMER_FLAG_NONE | AVTIMER_FLAG_AUTO_DELETE);	    		
                    else
                        AVTimerRestart(process_quit_timer);
                }
            }
        }
#endif /* ENABLE_NETWORK*/

			memcpy(&DevMountInfo, (DEV_MOUNT_INFO*)pMsg->msg_value, sizeof(DEV_MOUNT_INFO));
			GetAddDevNodeItem(&DevItem, &DevMountInfo, ++DevMountNum);
			AddDevNode(DevItem, &DevList);

			if(strncmp(temp_mount_device_name,((DEV_MOUNT_INFO *)(pMsg->msg_value))->mount_device_name,4)== 0)
			{
				max_volume++;				
			}
			else
			{
				strcpy(temp_mount_device_name, ((DEV_MOUNT_INFO *)(pMsg->msg_value))->mount_device_name);
				strcpy(temp_mount_point_name,  ((DEV_MOUNT_INFO *)(pMsg->msg_value))->mount_point_name );
				max_volume = 1;
				strcat(temp_mount_point_name,"/");
			}
#if 0//def AUTO_PLAY//modified by Hexiang for music autoplay error 20071203		
			if((AWGetTopWindow(gpFocusWin) == AWFindWinCtrlByName(WinLogo)) ||(AWGetTopWindow(gpFocusWin) == AWFindWinCtrlByName(Win15Pic)))
			{

				if(!GetAutoRunPara())
				{
					strcpy(CurDriver, temp_mount_point_name);
					multi_vol_autorun = 1;			
				}			
			}
#endif			
			if(AWGetTopWindow(gpFocusWin)== AWFindWinCtrlByName(WinDeviceSelect))
			{
				hwnd = AWFindWinCtrlByName(WinDeviceSelectInfo);
				CurrentCursor = 0;
				if(hwnd)
					RefreshDevWindow(hwnd, CurrentCursor, 0);
			}
			break;
			

		
		case BM_DEVICE_POST_UNMOUNT:
			mount_type=((DEV_MOUNT_INFO *)(pMsg->msg_value))->mount_device_type;
			memcpy(&DevMountInfo, (DEV_MOUNT_INFO*)pMsg->msg_value, sizeof(DEV_MOUNT_INFO));
#if 0//def ENABLE_BLUETOOTH	

			if(strcmp(mount_type,"BTOPP")==0)
				break;
#endif
#ifdef ENABLE_NETWORK
        if (Is_Gallery(mount_type))
        {
            if (strcmp("FLI_GALLERY", mount_type) == 0)
			{                     
                Yahoo_already_connected = 0;
            } 
            else if(strcmp("PIC_GALLERY", mount_type) == 0)
            {
                Google_already_connected = 0;
            }
            else if(strcmp("FRAMECHANNEL", mount_type) == 0)
            {
                FrameChannel_already_connected = 0;
            }
        }
#endif /* ENABLE_NETWORK */

			RemoveDevNode((DEV_MOUNT_INFO*)pMsg->msg_value, &DevList, --DevMountNum);
			
			ONLYDIR_FLAG=0;
			if((AWGetTopWindow(gpFocusWin) == AWFindWinCtrlByName(WinSetup_net_menu)))
				break;
        
			if(upgrade_flag == 1)
				break;
			if(AWGetTopWindow(gpFocusWin)== AWFindWinCtrlByName(WinDeviceSelect))
			{	
				hwnd = AWFindWinCtrlByName(WinDeviceSelectInfo);
				if(hwnd)
					RefreshDevWindow(hwnd, CurrentCursor, 0);
			    if (strncmp(CurDriver, DevMountInfo.mount_point_name, 6) == 0)
			    {
			        CurDriverAutoSet();
			    }
				break;
			}
			//para[6]:just compare the root path, eg:"/mnt/C"
			if (strncmp(CurDriver, DevMountInfo.mount_point_name, 6) == 0)
			{
				if (CheckMediaPlaybackApp())
				{
					SetForceCloseMediaApp();
					CloseMediaPlaybackApp(0xff);
					AWClearPlaylist(MEDIA_GENERAL);
				}
                
                CurDriverAutoSet();

				SwitchFocus_UnMount();
				if (!PC_Connect)
				{
					INT8U pic_app_id;
					if (AWGetAppID(MEDIA_PIC, &pic_app_id) == 0)
					{     			
                		if (AWGetAppStatus(pic_app_id) != APP_RUNNING)
						{ 
							ReloadLogo();
							GUIShowWindow(WinDeviceSelect);
						}
					}
					//ReloadLogo(Logo_keyboard, sizeof(Logo_keyboard));
					//GUIShowWindow("WinDeviceSelect");
				}
			}
			break;
			
		case BM_DEVICE_PC_CONNECT:
			PC_Connect = 1;
			if (CheckMediaPlaybackApp())
			{
				SetForceCloseMediaApp();
				CloseMediaPlaybackApp(0xff);
			}
			else
			{
				GUIShowWindow(WinPeripheralDev);
			}
			break;
		case BM_DEVICE_PC_DISCONNECT:
			if (AWGetTopWindow(gpFocusWin)== AWFindWinCtrlByName(WinPeripheralDev))
			{
				PC_Connect = 0;
				PerpheralDevRemoved = 1;
				hwnd = AWFindWinCtrlByName(WinConPeripheralDev);
				AWClearRectTxt(hwnd->draw_info[1].draw_pos_x, hwnd->draw_info[1].draw_pos_y, hwnd->draw_info[1].draw_width, hwnd->draw_info[1].draw_height);
				hwnd->draw_info[1].draw_data = (INT32U) PC_DISCONNECT_STR;
				AWPostMessage(hwnd, WM_PAINT_DRAW_INFO, 1);
				AWPostMessage(hwnd, WM_PAINT_FINISH, 0);
			}
			else
			{
				GUIShowWindow(WinDeviceSelect);
			}
			break;


		default:
			break;
#if 0
            if((AWGetTopWindow(gpFocusWin) == AWFindWinCtrlByName("WinUpgrade"))){
                CHARSTR* temp;
                if(GetDriverNum()==0){ 
                    TFILELIST *pList = (TFILELIST *)AWFindWinCtrlByName("FileListView") ; 
                    pList->list_levels=0; /* need sync pList to real directory in this case */
                    GUIShowWindow("WinWarnMessageBox");
                }
                else{ 
                    TFILELIST *pList = (TFILELIST *)AWFindWinCtrlByName("FileListView") ; 
                    temp=FileNavGetCurrDir();
                    if (strncmp("/mnt/", temp, strlen(temp)) == 0){
                        if(AWGetTopWindow(gpFocusWin) != AWFindWinCtrlByName("WinLogo")) {
                            AWHideWindow((PHWND)AWGetTopWindow(gpFocusWin));
                            GUIShowWindow("WinLogo") ;
                        }    
                        /* current dir is "/mnt/", refresh FileList displaying */     
                        pList->list_levels=0; /* need sync pList to real directory in this case */
                        AWPostMessage((PHWND)pList, WM_T_FILELIST_REFRESH, 0) ;
                    }
                }    
            }

            break ;
#endif

    
	}    
    return;    
}    

void AWSysMsgProcess(AWMSG *pMsg)
{
    switch(pMsg->msg_type)
    {
        case MSG_INPUT_EVENT:
            if(pMsg->msg_id == WM_KEYDOWN)
            AWSysKeyProcess(&pMsg->msg_value) ;
            break ;
        case MSG_NOTIFICATION:
            AWSysNotificationProcess(pMsg) ;
            break ;
        case MSG_QUIT:
            AWSysQuitProcess(pMsg) ;
            break;
        case MSG_BROADCAST:
            AWSysBroadCastProcess(pMsg) ;
            break;
        default:
            break ;
    }
    
    return ;
}
void reset_file_node()
{
	PCMDSET pCmd;
	pCmd = AWCommandSetMalloc() ;
	pCmd->command_num = 1 ;
	pCmd->curr_executed_cmd_num = 0 ;
	pCmd->commands[0] = CM_RESET_CURPATHNODE ;
	pCmd->cmd_timeout_value[0] = 0 ;
	AWGetAppID(MEDIA_SYSTEM, &pCmd->app_id) ;
	pCmd->ExecuteResultProcess = SystemCommandResponse ;
	AWAddCommandSet(pCmd) ;	
	
}
